﻿
using System ;
using System.Drawing ;


namespace MskEdit.Msk.Representation
{

    public class PointField {
    
        private IntField intFieldX_ ;
        private IntField intFieldY_ ;


        private PointField( IntField intFieldX, IntField intFieldY ) {
            intFieldX_ = intFieldX ;
            intFieldY_ = intFieldY ;
        }


        public Point? TryFrom( string line, Point? fallbackValue ) {

            int? x = intFieldX_.TryFrom( line, null ) ;
            if ( ! x.HasValue )
                return fallbackValue ;
                
            int? y = intFieldY_.TryFrom( line, null ) ;
            if ( ! y.HasValue )
                return fallbackValue ;
                
            return new Point( x.Value, y.Value ) ;
        }
        
        
        public string TryInsert( string line, Point point, string fallbackValue ) {
        
            string lineWithX = intFieldX_.TryInsert( line, point.X, null ) ;
            if ( lineWithX == null )
                return fallbackValue ;
                
            string lineWithXY = intFieldY_.TryInsert( lineWithX, point.Y, null ) ;
            if ( lineWithXY == null )
                return fallbackValue ;
                
            return lineWithXY ;
        }


        static public PointField XYk    = new PointField( IntField.Xk, IntField.Yk ) ;
    }
}
